<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>
<html>
<head>
    <title>我的订单 - 万万书城</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .header {
            background-color: #4CAF50;
            color: white;
            padding: 15px 0;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .header-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        .logo {
            font-size: 24px;
            font-weight: bold;
        }
        .nav a {
            color: white;
            text-decoration: none;
            margin: 0 15px;
        }
        .nav a:hover {
            text-decoration: underline;
        }
        .content {
            max-width: 1200px;
            margin: 20px auto;
            padding: 0 20px;
        }
        .order-container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 20px;
        }
        h2 {
            margin-top: 0;
            color: #333;
        }
        .order-item {
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .order-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
            margin-bottom: 15px;
        }
        .order-info {
            color: #666;
        }
        .order-status {
            padding: 5px 15px;
            background-color: #4CAF50;
            color: white;
            border-radius: 20px;
            font-size: 14px;
        }
        .order-content {
            margin-bottom: 15px;
        }
        .order-content table {
            width: 100%;
            border-collapse: collapse;
        }
        .order-content th, .order-content td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        .order-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .order-total {
            font-size: 18px;
            font-weight: bold;
            color: #e74c3c;
        }
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            text-decoration: none;
        }
        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }
        .btn-primary:hover {
            background-color: #45a049;
        }
        .empty-orders {
            text-align: center;
            padding: 50px;
            color: #666;
        }
        .user-info {
            color: white;
        }
        .user-info a {
            color: white;
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-container">
            <div class="logo">万万书城</div>
            <div class="nav">
                <a href="index.jsp">首页</a>
                <a href="cart">购物车</a>
                <a href="order?action=list">我的订单</a>
                <a href="userCenter">用户中心</a>
            </div>
            <div class="user-info">
                <% if (session.getAttribute("user") != null) {
                    com.wanwanbookstore.entity.User user = (com.wanwanbookstore.entity.User) session.getAttribute("user");
                    out.println(user.getUsername() + " <a href='logout'>退出</a>");
                } else {
                    out.println("<a href='login.jsp'>登录</a> <a href='register.jsp'>注册</a>");
                }
                %>
            </div>
        </div>
    </div>

    <div class="content">
        <div class="order-container">
            <h2>我的订单</h2>
            
            <c:if test="${empty orders}">
                <div class="empty-orders">
                    <p>您还没有订单</p>
                    <a href="index.jsp" class="btn btn-primary">去购物</a>
                </div>
            </c:if>

            <c:forEach items="${orders}" var="order">
                <div class="order-item">
                    <div class="order-header">
                        <div class="order-info">
                            订单号：${order.id}<br>
                            <fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss" />
                        </div>
                        <div class="order-status">${order.status}</div>
                    </div>
                    
                    <div class="order-content">
                        <table>
                            <tr>
                                <th>商品</th>
                                <th>单价</th>
                                <th>数量</th>
                                <th>小计</th>
                            </tr>
                            <c:forEach items="${order.orderItems}" var="item">
                                <tr>
                                    <td>${item.book.title}</td>
                                    <td>¥${item.price}</td>
                                    <td>${item.quantity}</td>
                                    <td>¥${item.totalPrice}</td>
                                </tr>
                            </c:forEach>
                        </table>
                    </div>
                    
                    <div class="order-footer">
                        <div>
                            收货地址：${order.address}<br>
                            联系电话：${order.phone}
                        </div>
                        <div>
                            <div class="order-total">总计：¥${order.totalPrice}</div>
                            <a href="order?action=detail&id=${order.id}" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>
</body>
</html>